﻿using UnityEngine;
using System.Collections;

public class D2_WALL_TEST_01 : RecieaveInputObject
{
    public GameObject preFabBall;
    public GameObject preFabBallBoom;
    public GameObject preFabAfterBoom;

    public Transform Ball_Goal;
    public Transform Ball_Start;
   
    public Transform r_1;
    public Transform r_2;
    public Transform r_3;
    


    public Animation Wall_Ani;

    public GameObject[] StepRoot;
    public GameObject[] StepRoot_l;
    public GameObject[] StepRoot_r;

    public override void AwakeObject()
    {
        m_Cam = Camera.main;      
    }

  
    void FireBall()
    {
        //Wall_Ani["Take 001"].speed = 1;
        //Wall_Ani.Sample();

        preFabBall.transform.position = Ball_Start.transform.position;

        preFabBall.gameObject.SetActive(true);
        preFabBallBoom.SetActive(false);
        preFabAfterBoom.SetActive(false);

        Vector3[] path = new Vector3[3] { Ball_Start.transform.position, r_1.position, Ball_Goal.position };//, new Vector3(3.674892f, 7.874672f, 112.2135f), Ball_Goal.position };


        iTween.MoveTo(preFabBall.gameObject, iTween.Hash("islocal", false, "path", path, "time", 2.0f, "easetype", "easeInQuad"
            , "oncompletetarget", gameObject, "oncomplete", "EndBall"));
    }

    void EndBall()
    {
        preFabBallBoom.SetActive(true);
        preFabBall.gameObject.SetActive(false);

        StartCoroutine("BreakWallAni", 0.2f);
    }


    IEnumerator BreakWallAni(float waitTime)
    {
        yield return new WaitForSeconds(waitTime);       

        preFabAfterBoom.SetActive(true);
        //preFabBallBoom.gameObject.SetActive(false);
        BreakWall();
        //StartCoroutine("RewindWallAni", 5.5f);
    }
   

    int step = 1;
    void BreakWall()
    {
        for(int i = 0 ; i < 3 ; i++)
        {
            StepRoot[i].SetActive(step == i);
            //StepRoot_l[i].SetActive(step == i);
            //StepRoot_r[i].SetActive(step == i);
        }
        step++;
        step %= 3;
    }


    public override void UpdateTouch()       // 터치 입력 받는 함수. ButtonTouch 외에 다른 작업할경우 오버라이드해서 구현 사용
    {
        if (Input.GetKeyUp(KeyCode.A))
        {
            FireBall();
        }

        if (Input.GetKeyUp(KeyCode.S))
        {
            BreakWall();
        }
    }
}
